import { defineConfig } from 'vite';
import UnoCSS from 'unocss/vite';
import vue from '@vitejs/plugin-vue';
import path from 'path';
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    UnoCSS(),
    // 自动导入vue、vue-router
    AutoImport({
      imports: [
        'vue',
        'vue-router',
        {
          'ant-design-vue/es': ['message', 'notification', 'Modal'],
        },
      ],
      dts: 'src/types/auto-imports.d.ts', // 生成类型声明文件
    }),
    // 自动导入组件
    Components({
      resolvers: [
        AntDesignVueResolver({
          importStyle: 'less',
          resolveIcons: true, // 自动导入图标
        }),
      ],
      dts: 'src/types/components.d.ts', // 生成组件类型声明
    }),
    // 自动引入svg
    createSvgIconsPlugin({
      iconDirs: [path.resolve(__dirname, './src/assets/icons')],
      symbolId: 'icon-[dir]-[name]',
    }),
  ],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src'),
    },
  },
  css: {
    preprocessorOptions: {
      less: {
        // modifyVars: antModifyVars(),
        javascriptEnabled: true,
      },
    },
  },
});
